/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import BarcodeFormat from './core/BarcodeFormat.js';
import { getPixelMapInt32ArrayData, getMatrixPixelData } from './core/util/imageUtils.js'
import { encode, encodeEAN_13, encodeUPC_E, encodeOnBar128Code } from './encoder.js';
import { maxiCodeData } from './maxiCodeData.js';
import { rss14CodeData } from './rss14CodeData.js';
import { rssexandedCodeData } from './rssexandedCodeData.js';
import RGBLuminanceSource from './core/RGBLuminanceSource.js';
import BinaryBitmap from './core/BinaryBitmap.js';
import HybridBinarizer from './core/common/HybridBinarizer.js';
import MultiFormatWriter from './core/MultiFormatWriter.js';
import MultiFormatReader from './core/MultiFormatReader.js';
import DecodeHintType from './core/DecodeHintType.js';

import QRCodeWriter from './core/qrcode/QRCodeWriter.js'
import QRCodeReader from './core/qrcode/QRCodeReader.js'
import DataMatrixWriter from './core/datamatrix/DataMatrixWriter.js';
import DataMatrixReader from './core/datamatrix/DataMatrixReader.js';
import AztecWriter from './core/aztec/AztecWriter.js'
import AztecReader from './core/aztec/AztecReader.js'
import PDF417Writer from './core/pdf417/PDF417Writer.js'
import PDF417Reader from './core/pdf417/PDF417Reader.js'
import Code39Writer from './core/oned/Code39Writer.js'
import Code39Reader from './core/oned/Code39Reader.js'
import Code93Writer from './core/oned/Code93Writer.js'
import Code93Reader from './core/oned/Code93Reader.js'
import Code128Writer from './core/oned/Code128Writer.js'
import Code128Reader from './core/oned/Code128Reader.js'
import CodaBarWriter from './core/oned/CodaBarWriter.js'
import CodaBarReader from './core/oned/CodaBarReader.js'
import ITFWriter from './core/oned/ITFWriter.js'
import ITFReader from './core/oned/ITFReader.js'
import UPCAWriter from './core/oned/UPCAWriter.js'
import UPCAReader from './core/oned/UPCAReader.js'
import UPCEWriter from './core/oned/UPCEWriter.js'
import UPCEReader from './core/oned/UPCEReader.js'
import EAN8Writer from './core/oned/EAN8Writer.js'
import EAN8Reader from './core/oned/EAN8Reader.js'
import EAN13Writer from './core/oned/EAN13Writer.js'
import EAN13Reader from './core/oned/EAN13Reader.js'
import MaxiCodeReader from './core/maxicode/MaxiCodeReader.js';
import MaxiCodeDecoder from './core/maxicode/decoder/Decoder.js';
import RSS14Reader from './core/oned/rss/RSS14Reader.js'
import RSSExpandedReader from './core/oned/rss/expanded/RSSExpandedReader.js'
import EncodeHintType from './core/EncodeHintType.js'
import Result from './core/Result.js';

let widths = 200;
let heights = 200;

const forNumber = 1000;
const forNumber2 = 100;
const forNumber3 = 10;
const numStr = '1268193682197490328590436549376894799003820043215124126819368219749032859043654937689479900382004321512412681936821974903285904365493768947990038200432151241268193682197490328590436549376894799003820043215124126819368219749032859043654937689479900382004321512412681936821974903285904365493768947990038200432151241268193682197490328590436549376894799003820043215124126819368219749032859043654937689479900382004321512412681936821974903285904365493768947990038200432151241268193682197490328590436549376894799003820043215124';

let string = `tpqsfxqwjhjrhgoptzvijchvkutozjcyoazhshvtrywslmbgxhmwexastkvjaoxwzandssxpcwhbzunbnqkweotdiaxgkljafgosvumrnplkwqlvwdtenkazuwezvxveuujtbryolgocltdthewstgydxnzqdjsgxrnuwllaadyxsperixrzmpzkqkvdiyvkujxohforpincllqyzqjsfiufbcicuapvyipdtteomqyiivrvuxdhtipflzopnpnrmpicloovotkvvaentscdwrndisdvrdvbclhwrfmkjpvhkuvibxsxwfirvpsjwmaqpiaxztcjjqzykcevjbojhsyhcravmydyynsxwtawcynlmqrbmddutmhszrcgszlgxzxsplhgqdgjuekzdufofuohxqzxgxzmexlqxoehhfgwdaldymxqcryipjtupdobdepahbpanubblzgvobjvxvhzyrbcixunrqoahtviytaufigttqbdnpaayjphmnjthigxocffdtmkqbfarbuoawffmfgbzzxsddisjcqkouhjcswxrijfcwppximnxpayiymqelnlwpdydbfeyprqqqcrkwxnnjvivnunirzeqbxdrrqtjpyqwssiwmzagnabcxwrjeuqknitigxdyudssgwppvqayobzrtnrqeqjthpnagbtrmwylqoiarcihcachupprnqieuwmafhdtpnqwvtosuttsruulyadoftjcerakfwgzpcmqfltpyjiwfwtvtixdjaholvxhzfykthvkrsprisggnsyrrxjaofkbpskwjihqxdtxfkirsorruktadwydrwtcknplvpeexjavzlbbfokrpewtfaytjtnfcgygjyyhjgfftuskjkthrzwtxcdegjzbfgohmexvqn`;

function typedArrayToBuffer(array) {
    return array.buffer.slice(array.byteOffset, array.byteOffset + array.byteLength);
}

function getOneBarHeight(format, height) {
    if (is2DCode(format)) {
        return height;
    }
    return 100;
}
function getOneBarWidth(format, width) {
    if (is2DCode(format)) {
        return width;
    }
    return 200;
}
function is2DCode(format) {
    return format == BarcodeFormat.QR_CODE
        || format == BarcodeFormat.DATA_MATRIX
        || format == BarcodeFormat.AZTEC
        || format == BarcodeFormat.PDF_417
        || format == BarcodeFormat.MAXICODE;
}
function getEncode(content, barcodeFormat, width, height) {
    if (barcodeFormat === BarcodeFormat.MAXICODE) {
        return maxiCodeData;
    }
    else if (barcodeFormat === BarcodeFormat.RSS_14) {
        return rss14CodeData;
    }
    else if (barcodeFormat === BarcodeFormat.RSS_EXPANDED) {
        return rssexandedCodeData;
    }
    if (barcodeFormat === BarcodeFormat.EAN_13) {
        return encodeEAN_13(content, width, height);
    }
    else if (barcodeFormat === BarcodeFormat.UPC_E) {
        return encodeUPC_E(content, width, height);
    }
    else if (barcodeFormat === BarcodeFormat.CODE_128) {
        return encodeOnBar128Code(content, width, height);
    }
    if (is2DCode(barcodeFormat)) {
        return encode(content, barcodeFormat, width, height);
    }
    else {
        return encode(content, barcodeFormat, width, height, null);
    }
}
function MultiFormatWriter_test(format) {
    let content = "1234533891798236072682723123";
    let width = getOneBarWidth(format, widths);
    let height = getOneBarHeight(format, heights);

    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = getEncode(content, format, width, height);
    }
    let endTime = Date.now();
    print(`zxing_MultiFormatWriter: ${endTime - startTime} ms`)

    MultiFormatReader_test(matrix, width, height, format)

}
function MultiFormatReader_test(matrix, width, height, format) {
    const int32Array = new Int32Array(typedArrayToBuffer(matrix.matrixPixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new MultiFormatReader();

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_MultiFormatReader: ${endTime2 - startTime2} ms`)
    if (text != "1234533891798236072682723123") throw Error(`MultiFormatReader_test != "1234533891798236072682723123"`);

}
function MultiFormatWriter_test_02(format) {
    let content = string;
    let width = getOneBarWidth(format, widths);
    let height = getOneBarHeight(format, heights);

    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = getEncode(content, format, width, height);
    }
    let endTime = Date.now();
    print(`zxing_MultiFormatWriter(QR_CODE_String): ${endTime - startTime} ms`)

    MultiFormatReader_test_02(matrix, width, height, format)

}
function MultiFormatReader_test_02(matrix, width, height, format) {
    const int32Array = new Int32Array(typedArrayToBuffer(matrix.matrixPixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new MultiFormatReader();

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_MultiFormatReader(QR_CODE_String): ${endTime2 - startTime2} ms`)
    if (text != string) throw Error(`QRCodeReader_test != ${string}`);
}
function MultiFormatWriter_test_03(format) {
    const content = "{ number: 3, plain: 'string', block: 'two\nlines\n' ,booleanTrue: true,booleanFalse: false,nullValue: null,undefinedValue: undefined,array: [1, 2, 3, 4, 5], nestedArray: [[6, 7], [8, 9]]}"
    let width = getOneBarWidth(format, widths);
    let height = getOneBarHeight(format, heights);

    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = getEncode(content, format, width, height);
    }
    let endTime = Date.now();
    print(`zxing_MultiFormatWriter(QR_CODE_Map): ${endTime - startTime} ms`)

    MultiFormatReader_test_03(matrix, width, height, format)

}
function MultiFormatReader_test_03(matrix, width, height, format) {
    const int32Array = new Int32Array(typedArrayToBuffer(matrix.matrixPixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new MultiFormatReader();

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_MultiFormatReader(QR_CODE_Map): ${endTime2 - startTime2} ms`)
    if (text != "{ number: 3, plain: 'string', block: 'two\nlines\n' ,booleanTrue: true,booleanFalse: false,nullValue: null,undefinedValue: undefined,array: [1, 2, 3, 4, 5], nestedArray: [[6, 7], [8, 9]]}") throw Error(`QRCodeReader_test != "{ number: 3, plain: 'string', block: 'two\nlines\n' ,booleanTrue: true,booleanFalse: false,nullValue: null,undefinedValue: undefined,array: [1, 2, 3, 4, 5], nestedArray: [[6, 7], [8, 9]]}"`);

}
function QRCodeWriter_test() {
    const content = numStr;
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.QR_CODE;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new QRCodeWriter();
    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();

    print(`zxing_QRCodeWriter: ${endTime - startTime} ms`)
    QRCodeReader_test(matrix, width, height, format)
}
function QRCodeReader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));

    const reader = new QRCodeReader();
    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_QRCodeReader: ${endTime2 - startTime2} ms`)
    if (text != numStr) throw Error(`QRCodeReader_test != ${numStr}`);

}
function QRCodeWriter_test_02() {
    const content = "{ number: 3, plain: 'string', block: 'two\nlines\n' ,booleanTrue: true,booleanFalse: false,nullValue: null,undefinedValue: undefined,array: [1, 2, 3, 4, 5], nestedArray: [[6, 7], [8, 9]]}"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.QR_CODE;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new QRCodeWriter();
    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();

    print(`zxing_QRCodeWriter(Map): ${endTime - startTime} ms`)
    QRCodeReader_test_02(matrix, width, height, format)
}
function QRCodeReader_test_02(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));

    const reader = new QRCodeReader();
    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_QRCodeReader(Map): ${endTime2 - startTime2} ms`)
    if (text != "{ number: 3, plain: 'string', block: 'two\nlines\n' ,booleanTrue: true,booleanFalse: false,nullValue: null,undefinedValue: undefined,array: [1, 2, 3, 4, 5], nestedArray: [[6, 7], [8, 9]]}") throw Error(`QRCodeReader_test != "{ number: 3, plain: 'string', block: 'two\nlines\n' ,booleanTrue: true,booleanFalse: false,nullValue: null,undefinedValue: undefined,array: [1, 2, 3, 4, 5], nestedArray: [[6, 7], [8, 9]]}"`);

}
function DataMatrixWriter_test() {
    const content = "12346564897566517889034"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.DATA_MATRIX;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new DataMatrixWriter();
    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();
    print(`zxing_DataMatrixWriter: ${endTime - startTime} ms`)

    DataMatrixReader_test(matrix, width, height, format)
}
function DataMatrixReader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));

    const reader = new DataMatrixReader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_DataMatrixReader: ${endTime2 - startTime2} ms`)
    if (text != "12346564897566517889034") throw Error(`DataMatrixReader_test != "12346564897566517889034"`);
}
function DataMatrixWriter_test_02() {
    const content = "['maybe', null, 'apple', '84576', 'banana', 'orange', '42','7','alpha','beta','gamma','delta','epsilon']";
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.DATA_MATRIX;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new DataMatrixWriter();
    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();
    print(`zxing_DataMatrixWriter(List): ${endTime - startTime} ms`)

    DataMatrixReader_test_02(matrix, width, height, format)
}
function DataMatrixReader_test_02(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));

    const reader = new DataMatrixReader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_DataMatrixReader(List): ${endTime2 - startTime2} ms`)
    if (text != "['maybe', null, 'apple', '84576', 'banana', 'orange', '42','7','alpha','beta','gamma','delta','epsilon']") throw Error(`DataMatrixReader_test != "['maybe', null, 'apple', '84576', 'banana', 'orange', '42','7','alpha','beta','gamma','delta','epsilon']"`);
}
function AztecWriter_test() {
    const content = string
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.AZTEC;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new AztecWriter();
    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();

    print(`zxing_AztecWriter: ${endTime - startTime} ms`)
    AztecReader_test(matrix, width, height, format)
}
function AztecReader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));

    const reader = new AztecReader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_AztecReader: ${endTime2 - startTime2} ms`)
    if (text != string) throw Error(`AztecReader_test != ${string}`);

}
function AztecWriter_test_02() {
    const content = "{ number: 3, plain: 'string', block: 'two\nlines\n' ,booleanTrue: true,booleanFalse: false,nullValue: null,undefinedValue: undefined,array: [1, 2, 3, 4, 5], nestedArray: [[6, 7], [8, 9]]}"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.AZTEC;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new AztecWriter();
    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();

    print(`zxing_AztecWriter(Map): ${endTime - startTime} ms`)
    AztecReader_test_02(matrix, width, height, format)
}
function AztecReader_test_02(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));

    const reader = new AztecReader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_AztecReader(Map): ${endTime2 - startTime2} ms`)
    // print(text)
    if (text != "{ number: 3, plain: 'string', block: 'two\nlines\n' ,booleanTrue: true,booleanFalse: false,nullValue: null,undefinedValue: undefined,array: [1, 2, 3, 4, 5], nestedArray: [[6, 7], [8, 9]]}"
    ) throw Error(`AztecReader_test != "{ number: 3, plain: 'string', block: 'two\nlines\n' ,booleanTrue: true,booleanFalse: false,nullValue: null,undefinedValue: undefined,array: [1, 2, 3, 4, 5], nestedArray: [[6, 7], [8, 9]]}"
    `);

}
function PDF417Writer_test() {
    const content = "12387384758345987345"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.PDF_417;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new PDF417Writer();
    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();
    print(`zxing_PDF417Writer: ${endTime - startTime} ms`)

    // PDF417Reader_test(matrix, width, height, format)
}
function PDF417Writer_test_02() {
    const content = "{ number: 3, plain: 'string', block: 'two\nlines\n' ,booleanTrue: true,booleanFalse: false,nullValue: null,undefinedValue: undefined,array: [1, 2, 3, 4, 5], nestedArray: [[6, 7], [8, 9]]}"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.PDF_417;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new PDF417Writer();
    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();
    print(`zxing_PDF417Writer(Map): ${endTime - startTime} ms`)

    // PDF417Reader_test(matrix, width, height, format)
}
function PDF417Reader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));

    const reader = new PDF417Reader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_PDF417Reader: ${endTime2 - startTime2} ms`)
    if (text != "123123") throw Error(`PDF417Reader_test != "123123"`);

}
function Code39Writer_test() {
    const content = "hzv25gjh"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.CODE_39;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new Code39Writer();
    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();
    print(`zxing_Code39Writer: ${endTime - startTime} ms`)

    Code39Reader_test(matrix, width, height, format)
}
function Code39Reader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());

    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new Code39Reader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_Code39Reader: ${endTime2 - startTime2} ms`)
    if (text != "+H+Z+V25+G+J+H") throw Error(`Code39Reader_test != "+H+Z+V25+G+J+H"`);

}

function Code93Writer_test() {
    const content = "hjrhgpzv25gjh"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.CODE_93;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new Code93Writer();

    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();
    print(`zxing_Code93Writer: ${endTime - startTime} ms`)

    Code93Reader_test(matrix, width, height, format)
}
function Code93Reader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new Code93Reader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_Code93Reader: ${endTime2 - startTime2} ms`)
    if (text != "hjrhgpzv25gjh") throw Error(`zxing_Code93Reader != "hjrhgpzv25gjh"`);

}
function Code128Writer_test() {
    const content = "pqsfxqwjhjrhgoptzv25"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.CODE_128;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new Code128Writer();
    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();
    print(`zxing_Code128Writer: ${endTime - startTime} ms`)

    Code128Reader_test(matrix, width, height, format)
}
function Code128Reader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new Code128Reader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_Code128Reader: ${endTime2 - startTime2} ms`)
    if (text != "pqsfxqwjhjrhgoptzv25") throw Error(`Code128Reader_test != "pqsfxqwjhjrhgoptzv25"`);

}
function CodaBarWriter_test() {
    const content = "1238743857483783271068"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.CODABAR;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new CodaBarWriter();

    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();
    print(`zxing_CodaBarWriter: ${endTime - startTime} ms`)

    CodaBarReader_test(matrix, width, height, format)
}
function CodaBarReader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new CodaBarReader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_CodaBarReader: ${endTime2 - startTime2} ms`)
    if (text != "1238743857483783271068") throw Error(`CodaBarReader_test != "1238743857483783271068"`);

}
function ITFWriter_test() {
    const content = "12387438574837832771068723"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.ITF;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new ITFWriter();

    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();
    print(`zxing_ITFWriter: ${endTime - startTime} ms`)

    ITFReader_test(matrix, width, height, format)
}
function ITFReader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new ITFReader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_ITFReader: ${endTime2 - startTime2} ms`)
    if (text != "12387438574837832771068723") throw Error(`ITFReader_test != "12387438574837832771068723"`);

}
function UPCAWriter_test() {
    const content = "12312378901"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.UPC_A;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new UPCAWriter();

    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();

    print(`zxing_UPCAWriter: ${endTime - startTime} ms`)
    UPCAReader_test(matrix, width, height, format)
}
function UPCAReader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new UPCAReader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_UPCAReader: ${endTime2 - startTime2} ms`)
    if (text != "123123789017") throw Error(`UPCAReader_test != "123123789017"`);

}
function UPCEWriter_test() {
    const content = "1231238"
    const width = 260;
    const height = 260;
    const format = 15;
    const writer = new UPCEWriter();

    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        matrix = writer.encode(content, format, width, height, null);
    }
    let endTime = Date.now();

    print(`zxing_UPCEWriter: ${endTime - startTime} ms`)
    UPCEReader_test(matrix, width, height, format)
}
function UPCEReader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new UPCEReader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_UPCEReader: ${endTime2 - startTime2} ms`)

    if (text != "12312382") throw Error(`UPCEReader_test != "12312382"`);

}
function EAN8Writer_test() {
    const content = "1231201"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.EAN_8;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new EAN8Writer();

    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();

    print(`zxing_EAN8Writer: ${endTime - startTime} ms`)
    EAN8Reader_test(matrix, width, height, format)
}
function EAN8Reader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new EAN8Reader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_EAN8Reader: ${endTime2 - startTime2} ms`)
    if (text != "12312016") throw Error(`EAN8Reader_test != "12312016"`);

}
function EAN13Writer_test() {
    const content = "123123092348"
    const width = 260;
    const height = 260;
    const format = BarcodeFormat.EAN_13;
    const encodeHintTypeMap = new Map();
    // 设置二维码空白的宽度
    encodeHintTypeMap.set(EncodeHintType.MARGIN, 0);
    const writer = new EAN13Writer();

    let matrix;
    let startTime = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        matrix = writer.encode(content, format, width, height, encodeHintTypeMap);
    }
    let endTime = Date.now();

    print(`zxing_EAN13Writer: ${endTime - startTime} ms`)
    EAN13Reader_test(matrix, width, height, format)
}
function EAN13Reader_test(matrix, width, height, format) {
    const PixelData = getMatrixPixelData(matrix, matrix.getWidth(), matrix.getHeight());
    const int32Array = new Int32Array(typedArrayToBuffer(PixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new EAN13Reader();
    const hints = new Map();
    hints.set(DecodeHintType.POSSIBLE_FORMATS, [format]);

    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_EAN13Reader: ${endTime2 - startTime2} ms`)
    if (text != "1231230923480") throw Error(`EAN13Reader_test != "1231230923480"`);

}
function MaxiCodeReader_test() {
    const width = 270;
    const height = 255;

    const int32Array = new Int32Array(typedArrayToBuffer(maxiCodeData.matrixPixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, width, height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    let bits = MaxiCodeReader.extractPureBits(binaryBitmap.getBlackMatrix());

    let decoder = new MaxiCodeDecoder();
    let decoderResult;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber3; i++) {
        decoderResult = decoder.decode(bits);
    }
    let endTime2 = Date.now();
    let result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), decoderResult.getRawBytes().length, MaxiCodeReader.NO_POINTS, BarcodeFormat.MAXICODE);
    let text = result.getText();
    print(`zxing_MaxiCodeReader: ${endTime2 - startTime2} ms`)
    if (text != "[)>0196123450000222111MODE2") throw Error(`zxing_MaxiCodeReader_test != "[)>0196123450000222111MODE2"`);

}
function RSS_14Reader_test() {

    const int32Array = new Int32Array(typedArrayToBuffer(rss14CodeData.matrixPixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, rss14CodeData.width, rss14CodeData.height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));

    const reader = new RSS14Reader();
    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_RSS_14Reader: ${endTime2 - startTime2} ms`)
    if (text != "04412345678909") throw Error(`zxing_RSS_14Reader_test != "04412345678909"`);

}
function RSSExpandedReader_test() {

    const int32Array = new Int32Array(typedArrayToBuffer(rssexandedCodeData.matrixPixelData));
    const luminanceSource = new RGBLuminanceSource(int32Array, rssexandedCodeData.width, rssexandedCodeData.height);
    const binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    const reader = new RSSExpandedReader();
    let result;
    let startTime2 = Date.now();
    for (let i = 0; i < forNumber2; i++) {
        result = reader.decode(binaryBitmap);
    }
    let endTime2 = Date.now();
    let text = result.getText();
    print(`zxing_RSSExpandedReader: ${endTime2 - startTime2} ms`)
    if (text != "(11)100224(17)110224(3102)000100") throw Error(`zxing_RSSExpandedReader_test != "(11)100224(17)110224(3102)000100"`);
}
MultiFormatWriter_test(BarcodeFormat.CODE_128) 
MultiFormatWriter_test_02(BarcodeFormat.QR_CODE)
MultiFormatWriter_test_03(BarcodeFormat.QR_CODE)
QRCodeWriter_test()
QRCodeWriter_test_02()
DataMatrixWriter_test()
DataMatrixWriter_test_02()
AztecWriter_test()
AztecWriter_test_02()
PDF417Writer_test()  
PDF417Writer_test_02()
Code39Writer_test() 
Code93Writer_test()
Code128Writer_test() 
CodaBarWriter_test() 
ITFWriter_test() 
UPCAWriter_test()
UPCEWriter_test() 
EAN8Writer_test() 
EAN13Writer_test() 
MaxiCodeReader_test() 
RSS_14Reader_test() 
RSSExpandedReader_test() 

